<template>
  <div>
    <a-button type="primary" class="choose-material"
              style="margin-left: 0; margin-bottom: 10px;"
              @click="showVideoMaterial()">从素材库选择视频
    </a-button>
    <div class="videoBox">
      <img style="width: 50%; height: 200px; cursor: pointer;" v-if="!videoInfo.videoUrl"
           src="~@assets/editDefault.png" title/>
      <div v-if="videoInfo.videoUrl">
        <video controls width="800px" height="300px" :poster="videoInfo.mbLogoUrl">
          <source :src="videoInfo.videoUrl" type="video/webm"/>
        </video>
      </div>
    </div>
    <j-modal
      width="60%"
      title="选择视频"
      :visible.sync="visible"
      @ok="handleOk">
      <a-input-search style="width: 50%" placeholder="请输入标签名称" v-model="queryParam.keyword"
                      @search="loadData(1)"></a-input-search>
      <a-spin :spinning="loading">
        <a-row>
          <a-col class="item" :span="4" v-for="(item) in dataSource" @click="checkItem(item)">
            <div class="item-img-container">
              <img class="item-img" :src="item.materialCoverUrl">
            </div>
            <div class="item-name">{{item.keyword}}</div>
            <a-radio class="item-radio" :checked="checkedItem.materialUrl===item.materialUrl"></a-radio>
          </a-col>
        </a-row>
      </a-spin>
      <a-pagination @change="loadData" style="text-align: right" v-model="ipagination.current"
                    :total="ipagination.total"
                    show-less-items></a-pagination>
    </j-modal>
  </div>
</template>

<script>
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'

  export default {
    name: "VideoChose",
    mixins: [JeecgListMixin],
    model: {
      prop: 'videoInfo',
      event: 'change'
    },
    props: ['videoInfo'],
    data() {
      return {
        visible: false,
        queryParam: {
          materialType: 2
        },
        url: {
          list: 'materia/crdMaterialInfo/list'
        },
        checkedItem: ''
      }
    },
    methods: {
      showVideoMaterial() {
        this.visible = true;
      },
      handleOk() {
        if (this.checkedItem) {
          const {materialCoverUrl, materialUrl} = this.checkedItem;
          const videoInfo = {
            videoUrl: materialUrl,
            mbLogoUrl: materialCoverUrl
          };
          this.$emit('change', videoInfo);
        }
      },
      getQueryField() {
        return ''
      },
      //选中某一条
      checkItem(item) {
        this.checkedItem = item;
      }
    }
  }
</script>

<style scoped lang="less">
  .item {
    position: relative;
    margin: 5px;
    overflow: hidden;

    &-img {
      width: 100%;
      max-height: 120px;

      &-container {
        display: flex;
        align-items: center;
        width: 100%;
        height: 120px;
        border: 1px dotted #ededed;
        background-color: rgba(153, 153, 153, 0.13);
      }
    }

    &-name {
      text-align: center;
    }

    &-radio {
      position: absolute;
      top: 5px;
      left: 10px;
    }
  }


</style>